package patrol.mobile.com.mobilepatrol.fragment;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.BindView;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.InitActivity;
import patrol.mobile.com.mobilepatrol.activity.LoginActivity;
import patrol.mobile.com.mobilepatrol.manager.UpdateManager;
import patrol.mobile.com.mobilepatrol.manager.UserManager;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.utils.Constants;
import patrol.mobile.com.mobilepatrol.utils.SPUtils;
import patrol.mobile.com.mobilepatrol.widget.dialog.AppleDialog;

import static patrol.mobile.com.mobilepatrol.utils.SPUtils.get;

/**
 * Created by apple on 17/9/29.
 */

public class SelfFragment extends BaseFragment {
    @BindView(R.id.tv_name)
    TextView tv_name;

    @BindView(R.id.tv_name2)
    TextView tv_name2;

    @BindView(R.id.tv_com)
    TextView tv_com;

    @BindView(R.id.rl_down)
    RelativeLayout rl_down;

    @BindView(R.id.rl_exit)
    RelativeLayout rl_exit;

    @BindView(R.id.rl_version)
    RelativeLayout rl_version;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_self;
    }

    @Override
    protected void initData() {
        tv_name.setText(UserManager.getUser((String) SPUtils.get(Constants.current_id, "")).ryname);
        tv_name2.setText("当前账户 : "+ UserManager.getUserName());
        tv_com.setText(UserManager.getUser((String) get(Constants.current_id,"")).bmname);


    }

    @Override
    protected void initListener() {
        rl_down.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(InitActivity.class);
                CommonUtil.openNewActivityAnim(getActivity(),false);
            }
        });
        rl_exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AppleDialog dialog = new AppleDialog(getActivity(),R.style.Dialog,"确定退出？");
                dialog.show();
                dialog.setmListener(new AppleDialog.SureListener() {
                    @Override
                    public void onSure() {
                        //清除当前用户信息
                        SPUtils.remove(getActivity(),Constants.current_id);
                        //清楚桥梁
                        startActivity(LoginActivity.class);
                        CommonUtil.openNewActivityAnim(getActivity(),true);
                    }
                });


            }
        });
        rl_version.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateManager.getUpdateManager().checkAppUpdate(getActivity(),true);
            }
        });
    }
    @Override
    public void initTitle() {
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText("个人中心");
    }
}
